from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-13 14:10:08.080552
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 13, Sep, 2022
Time: 14:10:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.4069
Nobs: 778.000 HQIC: -50.7383
Log likelihood: 9972.41 FPE: 7.49260e-23
AIC: -50.9456 Det(Omega_mle): 6.67902e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298845 0.054168 5.517 0.000
L1.Burgenland 0.107817 0.036105 2.986 0.003
L1.Kärnten -0.106653 0.019183 -5.560 0.000
L1.Niederösterreich 0.207094 0.075474 2.744 0.006
L1.Oberösterreich 0.107219 0.073013 1.468 0.142
L1.Salzburg 0.253660 0.038609 6.570 0.000
L1.Steiermark 0.038037 0.050334 0.756 0.450
L1.Tirol 0.106215 0.040808 2.603 0.009
L1.Vorarlberg -0.059917 0.035114 -1.706 0.088
L1.Wien 0.052154 0.064978 0.803 0.422
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059178 0.112379 0.527 0.598
L1.Burgenland -0.035896 0.074905 -0.479 0.632
L1.Kärnten 0.047472 0.039798 1.193 0.233
L1.Niederösterreich -0.177685 0.156581 -1.135 0.256
L1.Oberösterreich 0.397752 0.151475 2.626 0.009
L1.Salzburg 0.289710 0.080100 3.617 0.000
L1.Steiermark 0.107034 0.104424 1.025 0.305
L1.Tirol 0.313621 0.084661 3.704 0.000
L1.Vorarlberg 0.026917 0.072849 0.369 0.712
L1.Wien -0.020997 0.134805 -0.156 0.876
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191066 0.027824 6.867 0.000
L1.Burgenland 0.089844 0.018546 4.844 0.000
L1.Kärnten -0.008409 0.009854 -0.853 0.393
L1.Niederösterreich 0.262884 0.038768 6.781 0.000
L1.Oberösterreich 0.129802 0.037504 3.461 0.001
L1.Salzburg 0.046792 0.019832 2.359 0.018
L1.Steiermark 0.018106 0.025854 0.700 0.484
L1.Tirol 0.093512 0.020961 4.461 0.000
L1.Vorarlberg 0.059063 0.018037 3.275 0.001
L1.Wien 0.118351 0.033376 3.546 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110249 0.028353 3.888 0.000
L1.Burgenland 0.046099 0.018898 2.439 0.015
L1.Kärnten -0.015256 0.010041 -1.519 0.129
L1.Niederösterreich 0.195269 0.039505 4.943 0.000
L1.Oberösterreich 0.287466 0.038217 7.522 0.000
L1.Salzburg 0.112836 0.020209 5.583 0.000
L1.Steiermark 0.102066 0.026346 3.874 0.000
L1.Tirol 0.112879 0.021360 5.285 0.000
L1.Vorarlberg 0.069979 0.018380 3.807 0.000
L1.Wien -0.022194 0.034011 -0.653 0.514
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132148 0.051434 2.569 0.010
L1.Burgenland -0.052100 0.034282 -1.520 0.129
L1.Kärnten -0.039978 0.018215 -2.195 0.028
L1.Niederösterreich 0.172280 0.071664 2.404 0.016
L1.Oberösterreich 0.135025 0.069327 1.948 0.051
L1.Salzburg 0.287925 0.036660 7.854 0.000
L1.Steiermark 0.035270 0.047793 0.738 0.461
L1.Tirol 0.161601 0.038748 4.171 0.000
L1.Vorarlberg 0.100933 0.033342 3.027 0.002
L1.Wien 0.068856 0.061698 1.116 0.264
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058768 0.040962 1.435 0.151
L1.Burgenland 0.039513 0.027303 1.447 0.148
L1.Kärnten 0.051261 0.014506 3.534 0.000
L1.Niederösterreich 0.223701 0.057074 3.920 0.000
L1.Oberösterreich 0.281557 0.055213 5.100 0.000
L1.Salzburg 0.048078 0.029196 1.647 0.100
L1.Steiermark -0.004055 0.038063 -0.107 0.915
L1.Tirol 0.147339 0.030859 4.775 0.000
L1.Vorarlberg 0.072907 0.026554 2.746 0.006
L1.Wien 0.081795 0.049136 1.665 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180751 0.048956 3.692 0.000
L1.Burgenland -0.006558 0.032631 -0.201 0.841
L1.Kärnten -0.061192 0.017337 -3.529 0.000
L1.Niederösterreich -0.084263 0.068212 -1.235 0.217
L1.Oberösterreich 0.194806 0.065988 2.952 0.003
L1.Salzburg 0.056707 0.034894 1.625 0.104
L1.Steiermark 0.232277 0.045491 5.106 0.000
L1.Tirol 0.493226 0.036881 13.373 0.000
L1.Vorarlberg 0.048550 0.031736 1.530 0.126
L1.Wien -0.052087 0.058726 -0.887 0.375
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166478 0.056165 2.964 0.003
L1.Burgenland -0.009225 0.037436 -0.246 0.805
L1.Kärnten 0.067097 0.019890 3.373 0.001
L1.Niederösterreich 0.203933 0.078256 2.606 0.009
L1.Oberösterreich -0.074121 0.075704 -0.979 0.328
L1.Salzburg 0.211713 0.040032 5.289 0.000
L1.Steiermark 0.117293 0.052189 2.247 0.025
L1.Tirol 0.072523 0.042312 1.714 0.087
L1.Vorarlberg 0.122515 0.036408 3.365 0.001
L1.Wien 0.123392 0.067373 1.831 0.067
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357681 0.032540 10.992 0.000
L1.Burgenland 0.005400 0.021689 0.249 0.803
L1.Kärnten -0.023591 0.011524 -2.047 0.041
L1.Niederösterreich 0.217370 0.045339 4.794 0.000
L1.Oberösterreich 0.184945 0.043861 4.217 0.000
L1.Salzburg 0.046989 0.023194 2.026 0.043
L1.Steiermark -0.016594 0.030237 -0.549 0.583
L1.Tirol 0.107357 0.024514 4.379 0.000
L1.Vorarlberg 0.073675 0.021094 3.493 0.000
L1.Wien 0.048074 0.039034 1.232 0.218
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040897 0.150828 0.193140 0.157272 0.125976 0.113084 0.067242 0.223256
Kärnten 0.040897 1.000000 -0.002959 0.131492 0.041640 0.096023 0.430560 -0.052786 0.100691
Niederösterreich 0.150828 -0.002959 1.000000 0.338085 0.152658 0.300252 0.107948 0.183579 0.324600
Oberösterreich 0.193140 0.131492 0.338085 1.000000 0.228516 0.332051 0.172578 0.167592 0.268506
Salzburg 0.157272 0.041640 0.152658 0.228516 1.000000 0.146928 0.123504 0.147533 0.133806
Steiermark 0.125976 0.096023 0.300252 0.332051 0.146928 1.000000 0.153010 0.138737 0.079794
Tirol 0.113084 0.430560 0.107948 0.172578 0.123504 0.153010 1.000000 0.113791 0.153565
Vorarlberg 0.067242 -0.052786 0.183579 0.167592 0.147533 0.138737 0.113791 1.000000 0.006573
Wien 0.223256 0.100691 0.324600 0.268506 0.133806 0.079794 0.153565 0.006573 1.000000